/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dinotrack.struts;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author alquad
 */
public class LoginForm extends org.apache.struts.action.ActionForm {
    
    private String usuario;
    private String contrasenia;
    private String error;
    private int loginResult;
    public final static int LOGIN = 0;
    public final static int NOT_LOGIN = 1;

    /**
     * @return the usuario
     */
    public String getUsuario() {
        return usuario;
    }

    /**
     * @param usuario the usuario to set
     */
    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    /**
     * @return the contraseña
     */
    public String getContrasenia() {
        return contrasenia;
    }

    /**
     * @param contraseña the contraseña to set
     */
    public void setContrasenia(String contraseña) {
        this.contrasenia = contraseña;
    }
    
    public String getError() {
        return error;
    }

    /**
     * @param error the error to set
     */
    public void setError(String error) {
        this.error = error;
    }

    /**
     * @return the loginResult
     */
    public int getLoginResult() {
        return loginResult;
    }

    /**
     * @param loginResult the loginResult to set
     */
    public void setLoginResult(int loginResult) {
        this.loginResult = loginResult;
    }

    public void setError() {
        this.setError("<span style='color:red'>Por favor, ingrese los datos solicitados.</span>");
    }

    /**
     *
     */
    public LoginForm() {
        super();
        this.loginResult=NOT_LOGIN;
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 
        ActionErrors errors = new ActionErrors(); 
        if (getUsuario() == null || getUsuario().length() < 1) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }
        return errors;
    }
}
